﻿<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:primitives="clr-namespace:Schedule.Primitives"
    xmlns:local="clr-namespace:Schedule"
    xmlns:diagnostics="clr-namespace:System.Diagnostics;assembly=WindowsBase"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d"
    x:Class="Schedule.Generic">
    
    <local:ScheduleEndOfDayConverter x:Key="ScheduleEndOfDayConverter" />
    <local:ScheduleNameOfDayConverter x:Key="ScheduleNameOfDayConverter" />

    <Style x:Key="{x:Type primitives:TimeItem}" TargetType="{x:Type primitives:TimeItem}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type primitives:TimeItem}">
                    <!-- hier kan je selectie doen, evt ook achtergrond enzo -->
                    <Border>
                        <StackPanel>
                            <ContentPresenter />
                        </StackPanel>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="ScheduleCellStyle" TargetType="{x:Type primitives:TimeItem}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type primitives:TimeItem}">
                    <Grid Background="#3FC8C8C8" SnapsToDevicePixels="True" Height="100">
                        <Rectangle Fill="#FFC8C8C8" Height="1" VerticalAlignment="Top"/>
                        <Rectangle Fill="#7FC8C8C8" VerticalAlignment="Center" Height="1"/>
                        <Rectangle Fill="#FFC8C8C8" Width="1" HorizontalAlignment="Left"/>
                        <Rectangle Fill="#FFC8C8C8" HorizontalAlignment="Right" Width="1"/>
                        <ContentPresenter />
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="ScheduleHeaderStyle" TargetType="{x:Type primitives:TimeItem}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type primitives:TimeItem}">
                    <Grid x:Name="PART_Root" SnapsToDevicePixels="True">
                        <StackPanel Orientation="Horizontal">
                            <TextBlock FontSize="16" FontWeight="Bold" Foreground="#FF494949" Width="20" TextAlignment="Right" Margin="0,0,3,0">
                    <TextBlock.Text>
                        <Binding Path="(primitives:TimePanel.ItemStart)" StringFormat="{}{0:HH}">
                            <Binding.RelativeSource>
                                <RelativeSource Mode="TemplatedParent" />
                            </Binding.RelativeSource>
                        </Binding>
                    </TextBlock.Text>
                            </TextBlock>
                            <TextBlock Foreground="#FF494949" Width="20" Margin="0,2,0,0">
                    <TextBlock.Text>
                        <Binding Path="(primitives:TimePanel.ItemStart)" StringFormat="{}{0:mm}">
                            <Binding.RelativeSource>
                                <RelativeSource Mode="TemplatedParent" />
                            </Binding.RelativeSource>
                        </Binding>
                    </TextBlock.Text>
                            </TextBlock>
                        </StackPanel>
                        <Rectangle Fill="#FFC8C8C8" Height="1" VerticalAlignment="Top"/>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="ScheduleItemStyle" TargetType="{x:Type primitives:TimeItem}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type primitives:TimeItem}">
                    <Grid d:DesignWidth="250" d:DesignHeight="200" SnapsToDevicePixels="True">
                        <Border CornerRadius="5" BorderThickness="1" Margin="3,0" Padding="5">
                            <Border.Effect>
                                <DropShadowEffect Opacity="0.5"/>
                            </Border.Effect>
                            <Border.BorderBrush>
                                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                    <GradientStop Color="#FF575757" Offset="0"/>
                                    <GradientStop Color="#FFBDBDBD" Offset="1"/>
                                </LinearGradientBrush>
                            </Border.BorderBrush>
                            <Border.Background>
                                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                    <GradientStop Color="#FFE6E6E6" Offset="0.5"/>
                                    <GradientStop Color="#FF767676" Offset="1"/>
                                    <GradientStop Color="#FFAFACAC"/>
                                    <GradientStop Color="#FFB3B3B3" Offset="0.586"/>
                                </LinearGradientBrush>
                            </Border.Background>
                            <Border.ToolTip>
                                <Grid>
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="Auto"/>
                                        <RowDefinition Height="Auto"/>
                                        <RowDefinition Height="Auto"/>
                                        <RowDefinition Height="Auto"/>
                                    </Grid.RowDefinitions>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="Auto" />
                                        <ColumnDefinition Width="Auto" />
                                    </Grid.ColumnDefinitions>
                                    <TextBlock Grid.ColumnSpan="2" Grid.Row="0" Text="{Binding Title}" Foreground="#FF494949" FontWeight="Bold" />
                                    <TextBlock Grid.ColumnSpan="2" Grid.Row="1" Text="{Binding Summary}" Foreground="#FF494949" />
                                    <TextBlock Grid.Column="0" Grid.Row="2" Text="Start: " Foreground="#FF494949" />
                                    <TextBlock Grid.Column="0" Grid.Row="3" Text="End: " Foreground="#FF494949" />
                                    <TextBlock Grid.Column="1" Grid.Row="2" Text="{Binding Start, StringFormat=0:HH:mm dd-MM-yyyy}" Foreground="#FF494949" />
                                    <TextBlock Grid.Column="1" Grid.Row="3" Text="{Binding End, StringFormat=0:HH:mm dd-MM-yyyy}" Foreground="#FF494949" />
                                </Grid>
                            </Border.ToolTip>
                            <StackPanel>
                                <TextBlock Text="{Binding Title}" Foreground="#FF494949" FontWeight="Bold" />
                                <TextBlock Text="{Binding Summary}" Foreground="#FF494949" />
                                <ContentPresenter />
                            </StackPanel>
                        </Border>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    
    <Style x:Key="{x:Type local:Schedule}" TargetType="{x:Type local:Schedule}">
        <Setter Property="ItemContainerStyle">
            <Setter.Value>
                <StaticResource ResourceKey="ScheduleItemStyle" />
            </Setter.Value>
        </Setter>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type local:Schedule}">
                    <ScrollViewer>
                        <Border>
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="50" />
                                    <ColumnDefinition Width="*" />
                                </Grid.ColumnDefinitions>
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="250" />
                                    <RowDefinition Height="*" />
                                </Grid.RowDefinitions>
                                <primitives:TimeItemsPresenter Name="PART_HEADER" Panel.ZIndex="0" Grid.Column="0" Grid.Row="1" ItemContainerStyle="{StaticResource ScheduleHeaderStyle}" />
                                <primitives:TimeItemsPresenter Name="PART_CELLS" Panel.ZIndex="0" Grid.Column="1" Grid.Row="0" Grid.RowSpan="2" ItemContainerStyle="{StaticResource ScheduleCellStyle}" />
                                <ItemsPresenter Panel.ZIndex="1" Grid.Column="2" Grid.Row="0" Grid.RowSpan="2" />
                            </Grid>
                        </Border>
                    </ScrollViewer>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <GroupStyle x:Key="{x:Static local:Schedule.MonthGroupStyleKey}" HidesIfEmpty="False">
        <GroupStyle.Panel>
            <ItemsPanelTemplate>
                <UniformGrid Rows="6" Columns="7" />
            </ItemsPanelTemplate>
        </GroupStyle.Panel>
        <GroupStyle.HeaderTemplate>
            <DataTemplate>
                <TextBlock Text="{Binding}" />
            </DataTemplate>
        </GroupStyle.HeaderTemplate>
        <GroupStyle.ContainerStyle>
            <Style TargetType="{x:Type GroupItem}">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type GroupItem}">
                            <Border>
                                <StackPanel>
                                    <ContentPresenter />
                                    <ItemsPresenter />
                                </StackPanel>
                            </Border>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
        </GroupStyle.ContainerStyle>
    </GroupStyle>

    <GroupStyle x:Key="{x:Static local:Schedule.DaysGroupStyleKey}" HidesIfEmpty="False">
        <GroupStyle.Panel>
            <ItemsPanelTemplate>
                <UniformGrid Rows="1" />
            </ItemsPanelTemplate>
        </GroupStyle.Panel>
        <GroupStyle.HeaderTemplate>
            <DataTemplate>
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="*" />
                    </Grid.ColumnDefinitions>
                    <TextBlock Grid.Column="0"  Text="{Binding Path=Name.Day}" />
                    <TextBlock Grid.Column="1" TextAlignment="Center" Text="{Binding Path=Name, Converter={StaticResource ScheduleNameOfDayConverter}}" />
                </Grid>
            </DataTemplate>
        </GroupStyle.HeaderTemplate>
        <GroupStyle.ContainerStyle>
            <Style TargetType="{x:Type GroupItem}">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type GroupItem}">
                            <Border>
                                <StackPanel>
                                    <ContentPresenter />
                                    <ItemsPresenter />
                                </StackPanel>
                            </Border>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
        </GroupStyle.ContainerStyle>
    </GroupStyle>

    <GroupStyle x:Key="{x:Static local:Schedule.DayGroupStyleKey}" HidesIfEmpty="False">
        <GroupStyle.ContainerStyleSelector>
            <local:ScheduleDayContainerStyleSelector />
        </GroupStyle.ContainerStyleSelector>
        <GroupStyle.Panel>
            <ItemsPanelTemplate>
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*" />
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="250" />
                        <RowDefinition Height="*" />
                    </Grid.RowDefinitions>
                </Grid>
            </ItemsPanelTemplate>
        </GroupStyle.Panel>
        <GroupStyle.HeaderTemplate>
            <DataTemplate>

            </DataTemplate>
        </GroupStyle.HeaderTemplate>
    </GroupStyle>

    <Style x:Key="{x:Static local:Schedule.ChronicalStyleKey}" TargetType="{x:Type GroupItem}">
        <Setter Property="Grid.Row" Value="1" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type GroupItem}">
                    <Border>
                        <StackPanel>
                            <ContentPresenter />
                            <primitives:TimeItemsPresenter
                                ItemsSource="{Binding Items}" 
                                ItemContainerStyle="{Binding Path=ItemContainerStyle, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=primitives:TimeItemsPresenter}}"
                                primitives:TimePanel.ItemStart="{Binding Path=DataContext.Name, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=GroupItem, AncestorLevel=2}}" 
                                primitives:TimePanel.ItemEnd="{Binding Path=DataContext.Name, Converter={StaticResource ScheduleEndOfDayConverter}, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=GroupItem, AncestorLevel=2}}" />
                        </StackPanel>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="{x:Static local:Schedule.FlatStyleKey}" TargetType="{x:Type GroupItem}">
        <Setter Property="Grid.Row" Value="0" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type GroupItem}">
                    <Border>
                        <StackPanel>
                            <ContentPresenter />
                            <primitives:TimeItemsPresenter
                                ItemsSource="{Binding Items}"
                                ItemContainerStyle="{Binding Path=ItemContainerStyle, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=primitives:TimeItemsPresenter}}">
                                <primitives:TimeItemsPresenter.ItemsPanel>
                                    <ItemsPanelTemplate>
                                        <StackPanel />
                                    </ItemsPanelTemplate>
                                </primitives:TimeItemsPresenter.ItemsPanel>
                            </primitives:TimeItemsPresenter>
                        </StackPanel>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

</ResourceDictionary>
